<?php
/**
 *   TextReporter
 *   Display the result of test case in TextFormat
 */
class Reporter_Config extends Reporter{

    /**
     *    Make Report_Text sington
     */
    private static $instance = null;
    private function __construct(){}
    private function __clone(){}
    public static function getInstance(){
        if(!self::$instance instanceof self){
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     *    Paints the title only.
     *    @param string $test_name        Name class of test.
     *    @access public
     */
    function paintHeader($test_name) {
        print "$test_name\n";
    }

    /**
     *    Paints the end of the test with a summary of
     *    the passes and failures.
     *    @param string $test_name        Name class of test.
     *    @access public
     */
    function paintFooter($test_name) {
        if ($this->getFailCount() + $this->getExceptionCount() == 0) {
            print "OK\n";
        } else {
            print "FAILURES!!!\n";
        }
        print "Test cases run: " . $this->getTestCaseProgress() .
                "/" . $this->getTestCaseCount() .
                ", Passes: " . $this->getPassCount() .
                ", Failures: " . $this->getFailCount() .
                ", Exceptions: " . $this->getExceptionCount() . "\n";
    }

    /**
     *    Paints the test failure as a stack trace.
     *    @param string $message    Failure message displayed in
     *                              the context of the other tests.
     *    @access public
     */
    function paintFail($message) {
        parent::paintFail($message);
        print $this->getFailCount() . ") $message\n";
        $breadcrumb = $this->getTestList();
        array_shift($breadcrumb);
        print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
        print "\n";
    }

    /**
     *    Paints a PHP error or exception.
     *    @param string $message        Message to be shown.
     *    @access public
     *    @abstract
     */
    function paintError($message) {
        parent::paintError($message);
        print "Exception " . $this->getExceptionCount() . "!\n$message\n";
        $breadcrumb = $this->getTestList();
        array_shift($breadcrumb);
        print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
        print "\n";
    }

    /**
     *    Paints a PHP error or exception.
     *    @param Exception $exception      Exception to describe.
     *    @access public
     *    @abstract
     */
    function paintException($exception) {
        parent::paintException($exception);
        $message = 'Unexpected exception of type [' . get_class($exception) .
                '] with message ['. $exception->getMessage() .
                '] in ['. $exception->getFile() .
                ' line ' . $exception->getLine() . ']';
        print "Exception " . $this->getExceptionCount() . "!\n$message\n";
        $breadcrumb = $this->getTestList();
        array_shift($breadcrumb);
        print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
        print "\n";
    }


    /**
    *     Added for print txt information of test result
    *     2011-06-22
    *     @param string $test_name        name of current suite of case
    *     @access public
    */

    function paintGroupStart($test_name, $size) {
        parent::paintGroupStart($test_name,$size);
        echo str_repeat('   ',count($this->test_stack))."[Suite] ".$test_name."\n";
    }

    function paintGroupEnd($test_name) {
        echo str_repeat('   ',count($this->test_stack))."[Suite] ".$test_name."\n";
        parent::paintGroupEnd($test_name);
    }
    
    function paintCaseStart($case_name) {
        parent::paintCaseStart($case_name);
        echo str_repeat('   ',count($this->test_stack))."[Case] ".$case_name." running...\n";
    }

    function paintCaseEnd($case_name) {
        echo str_repeat('   ',count($this->test_stack))."       ".$case_name." done!!!\n";
        parent::paintCaseEnd($case_name);
    }
}
?>
